<script setup>
import VChart from "vue-echarts";
import {ref} from "vue";
import {http} from "@/api";
import DayLine from "@/views/photovoltaic-forecast/day-line.vue";
const baseDetail = ref({
  // 本周日均发电量 (kWh)
  week_power: 0,
  // 今日预测发电量 (kWh)
  today_power: 0,
  // 今日实际发电量 (kWh)
  today_actual_power: 0,
  // 装机容量 (kWh)
  installed_capacity: 0,
  // 准确率
  accuracy: 0,
  // 昨日预测发电量 (kWh)
  yesterday_power: 0,
  // 昨日实际发电量 (kWh)
  yesterday_actual_power: 0,
})
const baseDetailList = ref([])
const option1 = ref({
  backgroundColor: "#FFF",
  grid: {
    top: "50",
    bottom: "5",
    left: "0",
    right: "0",
    containLabel: true
  },
  tooltip: {
    trigger: "axis",
    label: {
      show: true,
    },
  },
  xAxis: {
    boundaryGap: true, //默认，坐标轴留白策略
    axisLine: {
      show: false,
    },
    splitLine: {
      show: false,
    },
    axisTick: {
      show: false,
      alignWithLabel: true,
    },
    data: [

    ],
  },
  yAxis: {
    axisLine: {
      show: false,
    },
    splitLine: {
      show: true,
      lineStyle: {
        type: "dashed",
        color: "rgba(33,148,246,0.2)",
      },
    },
    axisTick: {
      show: false,
    },
    splitArea: {
      show: false,
      areaStyle: {
        color: "rgb(245,250,254)",
      },
    },
  },
  legend: {
    show: true,
    right: "center",
    top: "10",
    textStyle: {
      color: "rgb(33,148,246)",
    },
    data: ["日前预测功率", "实际功率"],
  },
  series: [
    {
      name: '日前预测功率',
      type: "line",
      symbol: "circle",
      symbolSize: 2,
      smooth: true,
      lineStyle: {
        color: "rgb(33,148,246)",
      },
      itemStyle: {
        color: "rgb(33,148,246)",
        borderWidth: 1,
      },
      data: [

      ],
    },
    {
      name: '实际功率',
      type: "line",
      symbol: "circle",
      symbolSize: 2,
      smooth: true,
      lineStyle: {
        color: "rgb(236,217,28)",
      },
      itemStyle: {
        color: "rgb(236,217,28)",
        borderWidth: 1,
      },
      data: [

      ],
    },
  ],
})
http.pvForecastRel.list().then(res => {
  for (let key in baseDetail.value) {
    baseDetail.value[key] = res.data[key]
  }
  baseDetailList.value = res.data
})
http.pvForecastRelRecord.list({
  type: 'day'
}).then(res => {
  const data = res.data
  const xData = data.map(item => item.name)
  const yData1 = data.map(item => item.forecast_power)
  const yData2 = data.map(item => item.actual_power)
  option1.value.xAxis.data = xData
  option1.value.series[0].data = yData1
  option1.value.series[1].data = yData2
})
</script>

<template>
  <el-main>
    <el-row :gutter="20" style="margin-bottom: 20px;">
      <el-col :span="24">
        <el-card shadow="never"  style="height: 100%">
          <template #header>
            <div class="card-header">
              <span>基本信息</span>
            </div>
          </template>
          <el-row :gutter="12" style="margin-bottom: 20px">
            <el-col :span="8" v-for="item in baseDetailList">
              <el-statistic :title="item.description" :value="item.value" style="margin-bottom: 20px">
                <template #suffix>
                  <span class="unit">{{ item.unit }}</span>
                </template>
              </el-statistic>
            </el-col>
          </el-row>
        </el-card>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="24">
        <el-card shadow="never" style="height: 100%">
          <template #header>
            <div class="card-header">
              <span>功率趋势</span>
            </div>
          </template>
          <v-chart ref="echartsRef2" class="chart" style="height: 400px" :option="option1" autoresize />
        </el-card>
      </el-col>
    </el-row>
    <DayLine disabled/>
  </el-main>
</template>

<style  lang="scss">
.el-card {
  display: flex;
  flex-direction: column;
  position: relative;
  .el-card__body {
    flex-grow: 1;
  }
}
.chart {
  height: 100%;
}
.chart2{
  position: absolute;
  left: 0;
  top: 50px;
  width: 100%;
  height: 110%;
}
.buffer{
  width: 120px;
  height: 300px;
  position: relative;
  border: 3px solid cadetblue;
  margin: 20px 50px;
  .buffer-value {
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    bottom: 0;
    line-height: 300px;
    text-align: center;
    font-size: 28px;
    color: #0bcbb9;
    font-weight: bold;
    z-index: 99;
  }
  .buffer-content {
    width: 100%;
    position: absolute;
    left: 0;
    bottom: 0;
    height: 0;
    background-color:cadetblue ;
    transition: all 0.8s;
  }
  .buffer-icon {
    width: 40px;
    height: 15px;
    background-color:cadetblue ;
    position: absolute;
    left: 50%;
    top: -15px;
    transform: translateX(-50%);
  }
}
.buffer-total {
}

.unit {
  color: #0bcbb9;
}
</style>